<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">











<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>testnguice - Data Providers</title>
    <style type="text/css" media="all">
      @import url("./css/maven-base.css");
      @import url("./css/maven-theme.css");
      @import url("./css/site.css");
    </style>
    <link rel="stylesheet" href="./css/print.css" type="text/css" media="print" />
          <meta name="author" content="Simone Tripodi" />
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
      </head>
  <body class="composite">
    <div id="banner">
                    <span id="bannerLeft">
    
            TestNGuice
    
            </span>
                        <a href="http://www.asemantics.com/" id="bannerRight">
    
                                    <img src="http://www.asemantics.com/images/logo.gif" alt="" />
    
            </a>
            <div class="clear">
        <hr/>
      </div>
    </div>
    <div id="breadcrumbs">
          
  

  
    
  
  
    
            <div class="xleft">
        Last Published: 2009-03-22
                          |   
          Version: 1.1
                        </div>
            <div class="xright">            <a href="../testnguice/">Project Page</a>
            |
                <a href="../testnguice/downloads/list">Downloads</a>
            |
                <a href="http://testng.org/" class="externalLink">TestNG</a>
            |
                <a href="http://testng.org/doc/book.html" class="externalLink">TEH TestNG Book</a>
            |
                <a href="../google-guice/">Google Guice</a>
            |
                <a href="http://www.antlr.org/" class="externalLink">ANTLR</a>
            
  

  
    
  
  
    
  </div>
      <div class="clear">
        <hr/>
      </div>
    </div>
    <div id="leftColumn">
      <div id="navcolumn">
           
  

  
    
  
  
    
                   <h5>Injectlet</h5>
            <ul>
              
    <li class="none">
                    <a href="index.html">Introduction</a>
          </li>
              
          
              
      
            
            
              
            <li class="expanded">
                    <a href="">User's Guide</a>
                  <ul>
                  
    <li class="none">
                    <a href="inject.html">Injection and TestCases</a>
          </li>
                  
    <li class="none">
              <strong>Data Providers</strong>
        </li>
              </ul>
        </li>
          </ul>
              <h5>Project Documentation</h5>
            <ul>
              
                
              
      
            
      
            
      
            
      
            
      
            
      
            
      
            
      
              
        <li class="collapsed">
                    <a href="project-info.html">Project Information</a>
                </li>
              
                
              
      
            
      
            
      
            
      
            
      
            
      
            
      
            
      
            
      
            
      
            
      
            
      
              
        <li class="collapsed">
                    <a href="project-reports.html">Project Reports</a>
                </li>
          </ul>
                                           <a href="http://maven.apache.org/" title="Built by Maven" class="poweredBy">
            <img alt="Built by Maven" src="./images/logos/maven-feather.png"></img>
          </a>
                       
  

  
    
  
  
    
        </div>
    </div>
    <div id="bodyColumn">
      <div id="contentBox">
        <div class="section"><h2><a name="Data_Providers"></a>
Data Providers</h2>
<p>A Data Provider serves two purposes:
                <ul><li>Pass an arbitrary number of parametrs to a test method;</li>
<li>Test methods will be invoked many times with different data sets.</li>
</ul>
</p>
<div class="section"><h2><a name="CSV_based_Data_Provider"></a>
CSV based Data Provider</h2>
<p>This data provider is a <i>lazy</i>
 data provider that reads
                data set from a CSV file.<br />

                Suppose having follow test case:
                <div class="source"><pre>package org.mycompany.myapp;

class MyTestCase {

    public void justASimpleTest(java.lang.Date date, int integer) {
        if (logger.isDebugEnabled()) {
            logger.debug(&quot;Asserting data [&quot;
                    + date
                    + &quot;, &quot;
                    + integer
                    + &quot;]&quot;);
        }

        assert date != null;
        assert integer != 0;
    }

}</pre>
</div>

                which should be executed with a CSV Data Provider, first you need to annotate the test method:
                <div class="source"><pre>@org.testng.annotations.Test(
    dataProvider = com.asemantics.testnguice.providers.CsvDataProvider.DATA_PROVIDER_ID,
    dataProviderClass = com.asemantics.testnguice.providers.CsvDataProvider.class
)
public void justASimpleTest(java.lang.Date date, int integer) {
    ...
}</pre>
</div>

                So, for the method <code>org.mycompany.myapp.MyTestCase#justASimpleTest</code>,
                the <code>com.asemantics.testnguice.providers.CsvDataProvider</code> will look for <i>classpath</i>
's resource
                <code>org/mycompany/myapp/MyTestCase.justASimpleTest.test-data.csv</code>.</p>
<p>The CSV used format is the format described on <a href="http://en.wikipedia.org/wiki/Comma-separated_values" class="externalLink">wikipedia</a>
,
                with single and multi-line comment support, ignoring also empty lines. Follows a brief example:<div class="source"><pre># classpath's resource org/mycompany/myapp/MyTestCase.justASimpleTest.test-data.csv
-- it is strongly reccomended putting your test resources in src/test/resources
/*
    comments could be useful to describe table headers
    attach LICENSE header
    report svn tags
    describe the data set
*/

2008,   17
2008-09,     17
2008-09-17,17
2008-09-17T12,17
2008-09-17T12:00,17
2008-09-17T12:00:30,17</pre>
</div>
</p>
<p>Java objects of type <code>java.util.Date</code> are converted starting from an ISO subset representation; allowed patterns are: <div class="source"><pre>yyyy
yyyy-MM
yyyy-MM-dd
yyyy-MM-dd'T'HH
yyyy-MM-dd'T'HH:mm
yyyy-MM-dd'T'HH:mm:ss</pre>
</div>
</p>
</div>
</div>

      </div>
    </div>
    <div class="clear">
      <hr/>
    </div>
    <div id="footer">
      <div class="xright">&#169;  
          2009
    
          Asemantics S.r.l.
          
  

  
    
  
  
    
  </div>
      <div class="clear">
        <hr/>
      </div>
    </div>
  </body>
</html>
